<?php 
namespace app\index\model;
use think\Model;
use think\Db;

class UserClient extends Model
{
	

	public static function add($user_id, $client_id='')
	{
		  $res = Db::name('user_client')->insertGetId([
				'user_id' =>$user_id,
				'client_id' => $client_id,  
			]); 
		   self::updateClientForUser($user_id,$client_id);  
		   return $res;  

	}

   public static function getUidByClient($client_id='')
   {
   		 $client = Db::name('user_client')->where('client_id',$client_id)->find();
   		 if ($client) {
   		 	return $client->client_id; 
   		 }
   }

   public static function getClientIdByUid($user_id='')
   {
   		 $client = Db::name('user_client')->where('user_id',$user_id)->find();
   		 if ($client) {
   		 	return $client->user_id;    
   		 }
   }
  public static function deleteClientId($client_id='')
   {
   		 $boolean = Db::name('user_client')->where('client_id',$client_id)->delete();  
   		 return $boolean;  
   }

   public static function updateClientForUser($user_id='',$client_id)
   {   		
	   	 Db::name('user')->where('id',$user_id)->update(['client_id'=>$client_id]);  
   }


}